﻿using JetBrains.Annotations;

namespace Rsdn.Janus
{
    using System;
    using SmartApp;
    using TreeGrid;

    /// <summary>
    /// Draft Box Manager
    /// </summary>
    [Service(typeof(IDraftboxManager))]
    public class DraftboxManager : OutboxManagerBase, IDraftboxManager, IKeyedNode
    {
        public DraftboxManager(IServiceProvider serviceProvider) 
            : base(serviceProvider)
        {
            _newMessages = new NewMessageCollection(serviceProvider, this, true);

            _collections = new ITreeNode[]
                               {
                                   _newMessages
                               };
        }

        #region IKeyedNode Members

        /// <summary>
        /// Уникальный ключ в пределах одного уровня иерархии .
        /// </summary>
        /// <value></value>
        string IKeyedNode.Key
        {
            get { return GetType().Name; }
        }

        /// <summary>
        /// Gets the outbox form.
        /// </summary>
        /// <value>The outbox form.</value>
        [NotNull]
        public override IOutboxForm OutboxForm
        {
            get
            {
                if (_outboxForm == null)
                {
                    lock (_formLockFlag)
                    {
                        if (_outboxForm == null)
                        {
                            _outboxForm = new DraftboxDummyForm(ServiceProvider, this);
                        }
                    }
                }

                return _outboxForm;
            }
        }

        IOutboxForm IOutboxManagerBase.OutboxForm
        {
            get { return OutboxForm; }
        }

        #endregion

    }
}